package javatelephone;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * This program tests the mail system. A single phone communicates with the
 * program through System.in/System.out.
 */
public class MailSystemTester {
	public static void main(String[] args) throws IOException
        {
            String options = obtenerOpcionDeUsuario();
            if(options==null)
                return;
            if (options.equals("1"))
            {
                viewModeGraphic();  
            }
            else if(options.equals("2"))
            {
                viewModeConsole();
            }
            else
                System.out.println("Options incorrect..!!");
	}

    public static void viewModeConsole() throws IOException {
        Consola consola = new Consola();
        MailSystem system = new MailSystem(MAILBOX_COUNT);
        Telephone p = new Telephone(consola);
        Connection c = new Connection(system, p);
        p.run(c);
    }

    public static void viewModeGraphic() throws IOException {
        final FrameTelephone graphic = new FrameTelephone();
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                graphic.setVisible(true);
            }
        });
        MailSystem system = new MailSystem(MAILBOX_COUNT);
        Telephone p = new Telephone(graphic);
        Connection c = new Connection(system, p);
        p.run(c);
    }

    public static String obtenerOpcionDeUsuario() throws IOException {
        String options;
        System.out.println("1 Mode Graphics..\n");
        System.out.println("2 Mode Console \n");
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader (isr);
        options = br.readLine();
        return options;
    }
        
	private static final int MAILBOX_COUNT = 20;
}
